﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace CameraWin
{
    public partial class CameraPanel : UserControl
    {
        public event EventHandler OnPTZChange;
        public PTZType PTZ {  get; private set; }   
        public ICamera Camera { get;private set; }
        public CameraPanel()
        {
            InitializeComponent();
        }
        public void SetCamera(ICamera camera)
        {
            Camera = camera;
            if(Camera == null)
            {
                return;
            }
            Camera.PanelPlay = panel1.Handle;
            panelPTZ.Visible = Camera.Set.PTZ;
        }
        void PTZChange(PTZType ptz)
        {
            if(ptz == PTZ)
            {
                return;
            }
            PTZ = ptz;
            Camera.PTZ(PTZ);
            if(OnPTZChange != null)
            {
                OnPTZChange(this, null);
            }
        }
        private void pictureBoxUp_MouseDown(object sender, MouseEventArgs e)
        {
            PTZChange(PTZType.Up);
        }

        private void pictureBoxUp_MouseUp(object sender, MouseEventArgs e)
        {
            PTZChange( PTZType.Null);
        }

        private void pictureBoxDown_MouseDown(object sender, MouseEventArgs e)
        {
            PTZChange( PTZType.Down);
        }

        private void pictureBoxDown_MouseUp(object sender, MouseEventArgs e)
        {
            PTZChange( PTZType.Null);
        }

        private void pictureBoxLeft_MouseDown(object sender, MouseEventArgs e)
        {
            PTZChange( PTZType.Left);
        }

        private void pictureBoxLeft_MouseUp(object sender, MouseEventArgs e)
        {
            PTZChange( PTZType.Null);
        }

        private void pictureBoxRight_MouseDown(object sender, MouseEventArgs e)
        {
            PTZChange( PTZType.Right);
        }

        private void pictureBoxRight_MouseUp(object sender, MouseEventArgs e)
        {
            PTZChange( PTZType.Null);
        }
    }
}
